/*
 * Copyright (c) 2024. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
 * Morbi non lorem porttitor neque feugiat blandit. Ut vitae ipsum eget quam lacinia accumsan.
 * Etiam sed turpis ac ipsum condimentum fringilla. Maecenas magna.
 * Proin dapibus sapien vel ante. Aliquam erat volutpat. Pellentesque sagittis ligula eget metus.
 * Vestibulum commodo. Ut rhoncus gravida arcu.
 */

package com.scujj.cs6.controller;

import com.scujj.cs6.annotation.AuthCheck;
import com.scujj.cs6.common.Result;
import com.scujj.cs6.model.dto.file.FileUploadRequestDTO;
import com.scujj.cs6.model.vo.FileVo;
import com.scujj.cs6.service.FileService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * 文件接口
 */
@Tag(name = "文件接口")
@RestController
@RequestMapping("/file")
@RequiredArgsConstructor
@Slf4j
public class FileController {


    private final FileService fileService;


    /**
     * 上传图片作为头像
     *
     * @param requestDTO      上传请求
     * @param request           请求
     * @return {@link Result}<{@link FileVo}>
     */
    @PostMapping("/upload/image")
    @Operation(summary = "上传图片base64串", description = "上传图片base64串转换为图片作为用户头像")
    @ApiResponse(
            responseCode = "200",
            description = "成功",
            content = @Content(
                    mediaType = "application/json",
                    schema = @Schema(implementation = FileVo.class)
            )
    )
    @Parameter(name = "Authorization", description = "认证信息", required = true, in = ParameterIn.HEADER)
    @AuthCheck
    public Result<FileVo> uploadAvatar(@io.swagger.v3.oas.annotations.parameters.RequestBody(required = true) @RequestBody FileUploadRequestDTO requestDTO, HttpServletRequest request) {
        return fileService.uploadAvatar(requestDTO.getBase64Str(), request);
    }


}
